package com.ruoyi.ams.controller;


import com.ruoyi.ams.service.IAmsOwnAssetService;
import com.ruoyi.common.core.domain.model.AmsOwnAsset;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.security.annotation.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 资产所有方资产信息Controller
 *
 * @author yfkj
 * @date 2021-10-15
 */
@RestController
@RequestMapping("/ams/AmsOwnAsset")
public class AmsOwnAssetController extends BaseController {
    @Autowired
    private IAmsOwnAssetService amsOwnAssetService;

    /**
     * 查询资产所有方资产信息列表
     */
    @PreAuthorize
    //@PreAuthorize(hasPermi = "ams:AmsOwnAsset:list")
    @GetMapping("/list")
    public TableDataInfo list(AmsOwnAsset amsOwnAsset) {
        startPage();
        List<AmsOwnAsset> list = amsOwnAssetService.selectAmsOwnAssetList(amsOwnAsset);
        return getDataTable(list);
    }

    /**
     * 导出资产所有方资产信息列表
     */
    @PreAuthorize
    //@PreAuthorize(hasPermi = "ams:AmsOwnAsset:export")
    @Log(title = "资产所有方资产信息", businessType = BusinessType.EXPORT)
    @PostMapping(value="/export", produces = "application/octet-stream")
    public void export(HttpServletResponse response, AmsOwnAsset amsOwnAsset) throws IOException {
        List<AmsOwnAsset> list = amsOwnAssetService.selectAmsOwnAssetList(amsOwnAsset);
        ExcelUtil<AmsOwnAsset> util = new ExcelUtil<AmsOwnAsset>(AmsOwnAsset.class);
        util.exportExcel(response, list, "资产所有方资产信息数据");
    }

    /**
     * 获取资产所有方资产信息详细信息
     */
    @PreAuthorize
    //@PreAuthorize(hasPermi = "ams:AmsOwnAsset:query")
    @GetMapping(value = "/{ownAssetId}")
    public AjaxResult getInfo(@PathVariable("ownAssetId") Long ownAssetId) {
        return AjaxResult.success(amsOwnAssetService.selectAmsOwnAssetByOwnAssetId(ownAssetId));
    }

    /**
     * 新增资产所有方资产信息
     */
    @PreAuthorize
    //@PreAuthorize(hasPermi = "ams:AmsOwnAsset:add")
    @Log(title = "资产所有方资产信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AmsOwnAsset amsOwnAsset) {
        return toAjax(amsOwnAssetService.insertAmsOwnAsset(amsOwnAsset));
    }

    /**
     * 修改资产所有方资产信息
     */
    @PreAuthorize
    //@PreAuthorize(hasPermi = "ams:AmsOwnAsset:edit")
    @Log(title = "资产所有方资产信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AmsOwnAsset amsOwnAsset) {
        return toAjax(amsOwnAssetService.updateAmsOwnAsset(amsOwnAsset));
    }

    /**
     * 删除资产所有方资产信息
     */
    @PreAuthorize
    //@PreAuthorize(hasPermi = "ams:AmsOwnAsset:remove")
    @Log(title = "资产所有方资产信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ownAssetIds}")
    public AjaxResult remove(@PathVariable Long[] ownAssetIds) {
        return toAjax(amsOwnAssetService.deleteAmsOwnAssetByOwnAssetIds(ownAssetIds));
    }
}
